import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: asus
 * Date: 2025-01-22
 * Time: 10:13
 */
public class IsValid {
    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        for (char c :
                s.toCharArray()) {
            if (c == '(' || c == '[' || c == '{') {
                stack.push(c);
            } else {
                if (stack.isEmpty()) {
                    return false;
                }
                char t = stack.pop();
                if (t == '(' && c == ')' || t == '[' && c == ']' || t == '{' && c == '}') {
                    ;
                } else {
                    return false;
                }
            }
        }
        return stack.isEmpty();
    }


}
